using System.IO;
using HybridCLR.Editor;
using UnityEditor;
using UnityEditor.Build.Player;
using UnityEngine;

namespace GameMain.Editor.BuildPipeline
{
    public partial class BuildPipeline
    {
        private static void CompileDll(string buildDir, BuildTarget target)
        {
            var group = UnityEditor.BuildPipeline.GetBuildTargetGroup(target);

            Directory.CreateDirectory(buildDir);
            var scr = PlayerBuildInterface.CompilePlayerScripts(new ScriptCompilationSettings
            {
                group = group,
                target = target
            }, buildDir);
            foreach (var ass in scr.assemblies)
            {
                Debug.Log($"[BuildPipeline::CompileDll] Compile assemblies:{buildDir}/{ass}");
            }
        }

        private static void CompileDll(BuildTarget target)
        {
            var hotDllSrcDir = SettingsUtil.GetHotFixDllsOutputDirByTarget(target);
            CompileDll(hotDllSrcDir, target);
        }

        private static void CompileDllActiveBuildTarget()
        {
            CompileDll(EditorUserBuildSettings.activeBuildTarget);
        }

        private static void CompileDllWin64()
        {
            CompileDll(BuildTarget.StandaloneWindows64);
        }

        private static void CompileDllAndroid()
        {
            CompileDll(BuildTarget.Android);
        }

        private static void CompileDllIos()
        {
            CompileDll(BuildTarget.iOS);
        }
    }
}
